package com.medvalley.tcm.controller.admin.controller;

import com.medvalley.tcm.base.Result;
import com.medvalley.tcm.controller.BaseController;
import com.medvalley.tcm.controller.admin.vo.inputvo.SearchAdminUserInputVo;
import com.medvalley.tcm.controller.admin.vo.outputvo.PageDataOutputVo;
import com.medvalley.tcm.service.AdminUserService;
import com.medvalley.tcm.vo.inputvo.AdminUserInputVo;
import com.medvalley.tcm.vo.outputvo.AdminUserOutputVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminController")
@RequestMapping("/admin")
@Api("审核医生接口")

public class AdminController extends BaseController {

    @Autowired
    private AdminUserService adminUserService;

    @ApiOperation("注册")
    @RequestMapping(value = "/user/register", method = RequestMethod.POST)
    public Result register(@ModelAttribute AdminUserInputVo adminUserInputVo) {
        adminUserService.register(adminUserInputVo);
        return success();
    }

    @ApiOperation("登录")
    @RequestMapping(value = "/user/login", method = RequestMethod.POST)
    public Result login(@RequestParam("phone") String phone, @RequestParam("password") String password) {
        AdminUserOutputVo adminUserOutputVo = adminUserService.login(phone, password);
        return success(adminUserOutputVo);
    }

    @ApiOperation("检索")
    @RequestMapping(value = "/user/search", method = RequestMethod.POST)
    public Result searchAdminUser(@ModelAttribute  SearchAdminUserInputVo searchAdminUserInputVo) {
        PageDataOutputVo<com.medvalley.tcm.controller.admin.vo.outputvo.AdminUserOutputVo> pageDataOutputVo = adminUserService.search(searchAdminUserInputVo);
        return success(pageDataOutputVo);
    }

    @RequestMapping(value = "/user/detail", method = RequestMethod.GET)
    @ApiOperation("详情")
    public Result adminUserDetail(@RequestParam int id) {
        com.medvalley.tcm.controller.admin.vo.outputvo.AdminUserOutputVo adminUserOutputVo = adminUserService.detail(id);
        return success(adminUserOutputVo);
    }

    @RequestMapping(value = "/user/delete", method = RequestMethod.GET)
    @ApiOperation("删除")
    public Result delete(@RequestParam int id) {
        adminUserService.delete(id);
        return success();
    }

    @RequestMapping(value = "/user/update", method = RequestMethod.GET)
    @ApiOperation("更新")
    public Result update(@ModelAttribute AdminUserInputVo adminUserInputVo) {
        adminUserService.update(adminUserInputVo);
        return success();
    }


}
